// ===================================================================== Lazy
const confirm	= window.$Lazy.file(()=>import('@antd/confirm'))
const message	= window.$Lazy.file(()=>import('@antd/message'))
// ===================================================================== 导出 excel
const Index = function(api,option){
	let opt = {
		...option
	}
	let { param, query, isConfirm, init, type, isSock } = opt
	
	param = typeof param === 'function' ? param() : param
	query = typeof query === 'function' ? query() : query

	param = query ? query : { page:1, limit:window.$config.pageSize, 'export': 1, ...init, ...this.query, ...this.model,  ...param }
	
	const ajax = () => {
		if(type === 'post'){
			window.$http.submit(null,api, { param, loading:true, loadingText:'文件导出中...' }).then(({url})=>{
				if(isSock){		// 异步
					window.$fn.msg.warning('数据下载将由后台服务器操作执行，下载完成后请前往【消息-系统通知】查看', 3)
				}else {
					window.location.href = url
					message.then(f=>f.success('文件导出成功'))
				}
			})
		}else{
			window.$http.pull(null,api, { param, loading:true, loadingText:'文件导出中...' }).then(({url})=>{
				if(isSock){
					window.$fn.msg.warning('数据下载将由后台服务器操作执行，下载完成后请前往【消息-系统通知】查看', 3)
				}else {
					window.location.href = url
					message.then(f=>f.success('文件导出成功'))
				}
			})
		}
	}
	if(isConfirm){
		confirm.then(f=>f({ msg:`预计【${this.state.pag.total}】条数据，是否确认导出？`, onOk:ajax  }))
	}else{
		ajax()
	}
	
}

export default Index